lib.use(['element', 'form','laydate','searchInput'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.jquery;
    var formForm = layui.Form('formForm');
    var searchInput = layui.searchInput;
    var reqUrl="";
    var probId=common.util.getParam("probId");
    var id =common.util.getParam("id");
    var busStyle =common.util.getParam("busStyle");

    initControl();
    /**
     * 页面加载完成调用方法
     * 初始化方法可以写在这里
     */
    (function () {

        common.util.windowMode(probId||busStyle,'receiDetailList.html');
        if(id){
            //修改
            loadFormData();
            reqUrl='/fin/receiDetail/update';
        }else{
            //新增
            reqUrl='/fin/receiDetail/save';
            //设置新增初始值
            formForm.setData({
                receiDate:common.util.getDate,
                isValid:1,
                receiState:1,

            });
            proHeadInfo(probId);
            $('.disabled-row').hide();
        }
    })();


    /**
     * 页面控件初始化
     */
    function initControl() {
        //初始化日期控件

        //填冲下拉框数据字典
        //<select name="dbType" dist-name="sys.Ent_DbTypeEnum" config='{"data": [{"value": "全部","key": "0","index":"2"}],"selectedIndex": "1"}'></select>
        //config:{
        //    data:{[                 自定义下拉框数据
        //          value:'全部',      显示文字
        //          key:0,            值
        //          index:1           当前值需要插入位置(累加完自定义数据后再从下标从0计算)
        //          ]},
        //    selectedIndex:1         当前下拉框默然选中位置（下标从0计算)
        // }
        formForm.selectRender();


        if (!busStyle) {
            //预订单编码弹出窗口
            searchInput.render($.extend(SALE_PROB_HEAD_CONFIG_SINGLE, {
                dst: '#probNoSearchInput',
                done: function (obj, nextObj, datas) {
                    var data = {
                        probId: datas[0].id,
                        probNo: datas[0].probNo,
                        storeId: datas[0].probNo,
                        storeId:datas.data.storeId,
                        customerId: datas[0].customerId,
                        customerCode: datas[0].customerCode,
                        customerName: datas[0].customerName,
                        customerContactName: datas[0].customerContactName,
                        customerContactTel: datas[0].customerContactTel,
                        customerContactAdd: datas[0].customerContactAdd
                    }
                    form.val('formForm', data);
                }
            }));
        }


        /**
         * Form表单校验
         */
        form.verify({
            probNo: function(value, item){
                if(!value){
                    return '预订单编码不能为空';
                }
            },
            receiAmount: function(value, item){
                if(!value){
                    return '收款金额不能为空';
                }
            },
            payTypeName: function(value, item){
                if(!value){
                    return '收款类型不能为空';
                }
            },
            payMentName: function(value, item){
                if(!value){
                    return '收款名称不能为空';
                }
            },
            bankAccountName: function(value, item){
                if(!value){
                    return '收款银行名称不能为空';
                }
            },
        });
    }
    /**
     * 监听保存按钮
     */
    form.on('submit(addFormSubmitFilter)', function (data) {
        var param = formForm.getData();
        common.ajax.post(reqUrl, param, function (resp) {
            layer.alert('操作成功', function () {
                param['busStyle']=busStyle;
                common.util.returnWindow('receiDetailList.html',param)
            })
        });
        return false;
    });


    /**
     * 编辑时加载数据
     */
    function loadFormData() {
        var id = common.util.getParam('id');
        common.ajax.get('/fin/receiDetail/info/'+id, {}, function (resp) {
            var receiDetail = resp.receiDetail;
            formForm.setData(receiDetail);
            if(receiDetail.receiState == 2){
                common.util.disabledBtnInput();
            }
        });
    }



    //其它业务方法增加到下面

    /**加载预订单信息
     * @param probId
     */
    function proHeadInfo(probId){
        if(probId){
            common.ajax.get('/sale/probHead/info/'+probId, {}, function (resp) {
                var data={
                    probId:resp.data.id,
                    probNo:resp.data.probNo,
                    storeId:resp.data.storeId,
                    storeName:resp.data.storeName,
                    customerId:resp.data.customerId,
                    customerCode:resp.data.customerCode,
                    customerName:resp.data.customerName,
                    customerContactName:resp.data.customerContactName,
                    customerContactTel:resp.data.customerContactTel,
                    customerContactAdd:resp.data.customerContactAdd
                }
                form.val('formForm',data);
            });
        }
    }

});
